(define-module (staging jsonnet)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system trivial)
  #:use-module (guix git-download)
  #:use-module (guix utils))

(define-public jsonnet
  (package
    (name "jsonnet")
    (version "0.15.0")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/google/jsonnet.git")
                    (commit (string-append "v" version))))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "06imnpbc5mn1dis051f54q6nq80dbm51nhxmba61rdyhf1131ml8"))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f
       #:phases (modify-phases %standard-phases
                  (delete 'configure)
                  (replace 'install
                    (lambda* (#:key outputs #:allow-other-keys)
                      (let* ((out (assoc-ref outputs "out"))
                             (bin-dir (string-append out "/bin")))
                        (mkdir-p bin-dir)
                        (install-file "jsonnet" bin-dir)
                        #t))))))
    (native-search-paths
     (list (search-path-specification
            (variable "JSONNET_PATH")
            (files '("lib/jsonnet")))))
    (home-page "https://jsonnet.org/")
    (synopsis "Data templating language")
    (description
     "jsonnet is a data templating language for app and tool
developers. It extends the JavaScript Object Notation (JSON) with
variables, conditionals and functions.")
    (license license:asl2.0)))



(define-public grafonnet
  (let ((commit "c459106d2d2b583dd3a83f6c75eb52abee3af764")
        (revision "1"))
    (package
      (name "grafonnet")
      (version (git-version "0.0.1" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "https://github.com/grafana/grafonnet-lib.git")
                      (commit commit)))
                (sha256
                 (base32
                  "0xl7n9r5vmpb5302f3k8kw1npvq9dzg6d3n96rkm07rlxbs6ga0c"))))
      (build-system trivial-build-system)
      (arguments
       `(#:builder (begin
                     (use-modules (guix build utils))
                     (let* ((libname "grafonnet")
                            (source (assoc-ref %build-inputs "source"))
                            (out    (assoc-ref %outputs "out"))
                            (libdir (string-append out "/lib/jsonnet"))
                            (src (string-append source "/" libname))
                            (target (string-append libdir "/" libname)))
                       (copy-recursively src target)
                       #t))
         #:modules ((guix build utils))))
      (home-page "https://github.com/grafana/grafonnet-lib")
      (synopsis "Jsonnet library for generating Grafana dashboard files")
      (description
       "Grafonnet provides a simple way of writing Grafana
dashboards. It leverages the data templating language Jsonnet. It
enables you to write reusable components that you can use and reuse
for multiple dashboards.")
      (license license:asl2.0))))


